package cn.myjerry.io.convert;

import java.io.UnsupportedEncodingException;

public class ConvertDemo01 {
	public static void main(String[] args) throws UnsupportedEncodingException {
		String str = "中国";
		byte[] data = str.getBytes();
		// 字节数不完整
		System.out.println(new String(data, 0, 4));
	}
	/**
	 * 编码与解码字符集必须相同，否则乱码
	 * @throws UnsupportedEncodingException 
	 */
	public static void test1() throws UnsupportedEncodingException {
		String str = "中国";
		byte[] data = str.getBytes();
		System.out.println(new String(data));
		data = str.getBytes("GBK");	// 设定编码字符集
		System.out.println(new String(data));
		
		byte[] data1 = "中国".getBytes("GBK");
		str = new String(data1, "GBK");
		System.out.println(str);
	}
}
